//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Web.UI;
using System.Web.UI.WebControls;

namespace CommunityServer.Controls
{
    public interface IText
    {
        bool Visible {get;set;}
        string Text {get;set;}
        
        Control Control { get;}
    }

    /// <summary>
    /// CS Literal implemenation of Literal with IText
    /// </summary>
    public class CSLiteral : Literal, IText
    {
        public Control Control
        {
            get{ return this;}
        }
    }

    /// <summary>
    /// CS Label implemenation of Literal with IText
    /// </summary>
    public class CSLabel : Label, IText
    {
        public Control Control
        {
            get{ return this;}
        }
    }

    /// <summary>
    /// Literal helper wrapper for IText
    /// </summary>
    public class LiteralWrapper : IText
    {
        
        internal LiteralWrapper(Literal literal)
        {
            _literal = literal;
        }

        private Literal _literal = null;

        #region IText Members

        public bool Visible
        {
            get{   return _literal.Visible;}
            set{_literal.Visible = value;}
        }

        public string Text
        {
            get{return _literal.Text;}
            set{_literal.Text = value;}
        }

        public Control Control
        {
            get{return _literal;}
        }

        #endregion

    }


    /// <summary>
    /// Lable helper wrapper for IText
    /// </summary>
    public class LabelWrapper : IText
    {
        
        internal LabelWrapper(Label label)
        {
            _label = label;
        }

        private Label _label = null;

        #region IText Members

        public bool Visible
        {
            get{   return _label.Visible;}
            set{_label.Visible = value;}
        }

        public string Text
        {
            get{return _label.Text;}
            set{_label.Text = value;}
        }

        public Control Control
        {
            get{return _label;}
        }

        #endregion

    }


    public class TextControlHelper
    {
        private TextControlHelper(){}

        public static IText CreateLiteral(Literal lit)
        {
            return new LiteralWrapper(lit);
        }

        public static IText CreateLabel(Label label)
        {
            return new LabelWrapper(label);
        }

        public static IText Create(Control cntrl)
        {
            if(cntrl == null)
                return null;

            IText it = cntrl as IText;
            if(it == null)
            {
                if(cntrl is Literal)
                    it = new LiteralWrapper(cntrl as Literal);
                else if (cntrl is Label )
                    it = new LabelWrapper(cntrl as Label);
            }

            return it;
        }
    }


}